package com.weisw.polaris.admin.service.impl;

import com.weisw.polaris.admin.dao.MenuMapper;
import com.weisw.polaris.admin.dao.UserMapper;
import com.weisw.polaris.admin.model.Menu;
import com.weisw.polaris.admin.model.User;
import com.weisw.polaris.admin.service.MenuService;
import com.weisw.polaris.admin.service.UserService;
import com.weisw.polaris.common.util.DateTimeUtils;
import com.weisw.polaris.common.util.PoiUtils;
import com.weisw.polaris.core.exception.PolarisException;
import com.weisw.polaris.core.page.MybatisPageHelper;
import com.weisw.polaris.core.page.PageRequest;
import com.weisw.polaris.core.page.PageResult;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;


@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public Menu findByName(String s){
        return menuMapper.findByName(s);
    }

    @Override
    public int save(Menu record) {
        Integer id = null;
        if(record.getMenuId() == null || record.getMenuId() == 0) {
            // 新增用户
            menuMapper.insert(record);
            id = record.getMenuId();
        } else {
            // 更新用户信息
            menuMapper.updateByPrimaryKey(record);
        }
        // 更新用户角色
        if(id != null && id == 0) {
            return 1;
        }
        return id;
    }

    @Override
    public int delete(Menu record) {
        return menuMapper.deleteByPrimaryKey(record.getMenuId());
    }

    @Override
    public int delete(List<Menu> records) {
        for(Menu record:records) {
            delete(record);
        }
        return 1;
    }

    @Override
    public Menu findById(Integer id) {
        return menuMapper.selectByPrimaryKey(id);
    }


//    public List<Menu> getMenu(List idList) {
//        List<Menu> menuList = new List<Menu>();
//        for (Object id:idList){
//            menuList.add(menuMapper.selectByPrimaryKey(id));
//        }
//        return menuList;
//    }

    @Override
    public PageResult findPage(PageRequest pageRequest) throws PolarisException{
        return MybatisPageHelper.findPage(pageRequest,menuMapper);
    }
}
